<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const countPairs = ness => {
      let res = 0;
      const mod = 1000000007;
      // 两数之和的最大值不超过ness的最大值×2
      const MAX = Math.max(...ness) * 2;
      const map = new Map();
      for (let i = 0; i < ness.length; i++) {
        // j = j << 1 用来乘以2
        // 从1开始找相加等于2的幂的数
        for (let j = 1; j <= MAX; j = j << 1) {
          const num = map.get(j - ness[i]) || 0;
          res = (res + num) % mod;
        }
        // 将当前数放入map
        map.set(ness[i], (map.get(ness[i]) || 0) + 1);
      }
      return res;
    };
    console.log(countPairs(ness = [1, 3, 5, 7, 9])) 
  </script>
</body>

</html>